package com.sutuijingling.utils;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import org.apache.commons.lang.c;

public class a {
    public static boolean a = true;
    static Boolean b = null;

    public static String a(String str) {
        return b(" cat  " + str);
    }

    public static String a(String str, String str2) {
        return b(" echo '" + str2 + "' > " + str);
    }

    public static String a(String str, String str2, String str3) {
        String b = b(String.format(str3, new Object[]{str, str2}));
        if (c.b(b)) {
            b.b(" no ls res for file :" + str + " with nextfile:" + str2, new Object[0]);
            return null;
        }
        b.b(" found file ls res :" + str + " with content ::" + b, new Object[0]);
        Object[] split = b.replaceAll("\\t", " ").replaceAll(" +", " ").split(" ");
        b.b(" split res :" + c.a(split, ','), new Object[0]);
        b = split[1];
        String str4 = split[2];
        return b;
    }

    public static String a(String str, boolean z) {
        IOException e;
        Throwable th;
        InterruptedException e2;
        String str2 = null;
        Process exec;
        try {
            exec = Runtime.getRuntime().exec("su");
            try {
                DataOutputStream dataOutputStream = new DataOutputStream(exec.getOutputStream());
                dataOutputStream.writeBytes(" " + str + "  ");
                dataOutputStream.writeBytes("\nexit\n");
                dataOutputStream.flush();
                exec.waitFor();
                str2 = org.apache.commons.io.c.a(exec.getInputStream(), org.apache.commons.io.a.f);
                if (z) {
                    if (exec != null) {
                        exec.destroy();
                    }
                    return str2;
                }
                if (exec != null) {
                    exec.destroy();
                }
                return str2;
            } catch (IOException e3) {
                e = e3;
                try {
                    e.printStackTrace();
                    if (exec != null) {
                        exec.destroy();
                    }
                    return str2;
                } catch (Throwable th2) {
                    th = th2;
                    if (exec != null) {
                        exec.destroy();
                    }
                    throw th;
                }
            } catch (InterruptedException e4) {
                e2 = e4;
                e2.printStackTrace();
                if (exec != null) {
                    exec.destroy();
                }
                return str2;
            }
        } catch (IOException e5) {
            e = e5;
            exec = str2;
            e.printStackTrace();
            if (exec != null) {
                exec.destroy();
            }
            return str2;
        } catch (InterruptedException e6) {
            e2 = e6;
            exec = str2;
            e2.printStackTrace();
            if (exec != null) {
                exec.destroy();
            }
            return str2;
        } catch (Throwable th3) {
            exec = str2;
            th = th3;
            if (exec != null) {
                exec.destroy();
            }
            throw th;
        }
    }

    public static void a() {
        b("busybox reboot");
        c.c();
        b("reboot");
    }

    public static Boolean b() {
        if (b != null) {
            return b;
        }
        String b = b(" ps  | grep bluestack");
        b.b(">>>>  aux for next :" + b, new Object[0]);
        if (b == null || !b.contains("bluestack")) {
            b = Boolean.FALSE;
        } else {
            b = Boolean.TRUE;
        }
        return b;
    }

    public static String b(String str) {
        return a(str, true);
    }

    public static String b(String str, String str2) {
        if (a) {
            return b(String.format(" busybox chown -R %s:%s %s", new Object[]{str, str, str2}));
        }
        return b(String.format(" chown %s:%s %s", new Object[]{str, str, str2}));
    }

    public static String c() {
        return b("am start -n com.taobao.taobao/com.taobao.tao.RushPromotionMainActivity");
    }

    public static String c(String str) {
        return b(String.format(" ls -al %s", new Object[]{str}));
    }

    public static String c(String str, String str2) {
        return a(str, str2, " ls -nl %s | grep %s");
    }

    public static String d() {
        return b("am start -n com.taobao.taobao/com.taobao.tao.welcome.Welcome");
    }

    public static boolean d(String str) {
        String c = c(str);
        b.a(" ls res [%s], for file [%s]", c, str);
        return (c.b(c) || c.contains("No such file or directory ")) ? false : true;
    }

    public static String e() {
        return b("am start -n com.taobao.taobao/com.taobao.tao.homepage.MainActivity3");
    }

    public static String e(String str) {
        try {
            str = URLEncoder.encode(str, "UTF-8").replace("+", "%20");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return b(" am broadcast -a my.action.clipboard.copy.content -d '" + str + "' -n jp.jun_nama.test.utf7ime/.DSReceiver ");
    }

    public static String f() {
        return b("am start -n com.taobao.taobao/com.taobao.search.searchdoor.SearchDoorActivity ");
    }

    public static String f(String str) {
        return b("am start -n  com.taobao.taobao/com.taobao.browser.BrowserActivity -a android.intent.action.VIEW -d '" + str + "'");
    }

    public static String g() {
        return b("am start -n com.taobao.taobao/com.taobao.search.common.searchdoor.SearchDoorActivity ");
    }

    public static String h() {
        return b("am start -n com.taobao.taobao/com.taobao.tao.mytaobao.MyTaoBaoActivity");
    }

    public static String i() {
        return b("am start -n org.imei.mtk65xx/com.mayor.codeSig.CodeSigWindow");
    }

    public static String j() {
        return b("am start -n org.imei.mtk65xx/.Mtk65xx");
    }

    public static String k() {
        return b("am start -n jp.jun_nama.test.utf7ime/.ui.UserOperationActivity");
    }

    public static String l() {
        return b("am start -n jp.jun_nama.test.utf7ime/jp.jun_nama.test.utf7ime.xposed.XposedConfigActivity");
    }
}
